Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        titles: [],
        projectPath: '',
        loading: false,
        changeGlobal: false
    },
    mutations: {
        changeTitles(state, titles) {
            state.titles = titles
        },
        changePath(state, path) {
            state.projectPath = path;
            var separator = anLogin.$data.separator
            if (path.indexOf(separator + "src" + separator + "web") != -1) {
                state.projectPath = path.substring(0, path.indexOf(separator + "src" + separator + "web"));
            }
        },
        changeLoading(state, status) {
            state.loading = status;
        },
        changeGlobal(state, status) {
            state.changeGlobal = status;
        }
    }
})

Vue.prototype.openLoading = function () {
    this.$store.commit('changeLoading', true);
}
Vue.prototype.closeLoading = function () {
    this.$store.commit('changeLoading', false);
}

// 前端监听某个按钮点击复制 开源库clipboard
Vue.prototype.setCopyElem = function (className) {
    var that = this;
    var clipboard = new ClipboardJS(className);
    //成功回调
    clipboard.on('success', function(e) {
        that.$message({
            message: '内容已复制到粘贴板上',
            type: 'success'
        });
        e.clearSelection();
    });
    //失败回调
    clipboard.on('error', function(e) {
        that.$message({
            message: '内容复制失败',
            type: 'error'
        });
    });
}
// 前端直接复制内容 开源库clipboard
Vue.prototype.setCopyText = function (text, e) {
    var that = this;
    var clipboard = new ClipboardJS(e.target, {
        text: () => text
    });
    //成功回调
    clipboard.on('success', function(e) {
        that.$message({
            message: '内容已复制到粘贴板上',
            type: 'success'
        });
        e.clearSelection();
        clipboard.destroy()
    });
    //失败回调
    clipboard.on('error', function(e) {
        that.$message({
            message: '内容复制失败',
            type: 'error'
        });
        clipboard.destroy()
    });
    clipboard.onClick(e)
}

var anLogin = new Vue({
    el: '#app',
    data() {
    },
    store: store,
    mounted() {
        if (!this.$route.path || this.$route.path === '' || this.$route.path === '/') {
            this.$router.push({path: '/managerGit'});
        }
    },
    methods: {},
    router: new VueRouter({
        // mode: 'history', // 去掉url中的#
        routes: [
            {path: '/managerGit', component: managerGit},
            {path: '/managerVersion', component: managerVersion},
            {path: '/managerTag', component: managerTag},
            {path: '/tagPackage', component: tagPackage},
        ]
    })
})
